package com.ruoyi.web.controller.shelves;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.shelves.domain.Mk;
import com.ruoyi.shelves.service.IMkService;

/**
 * 模块Controller
 *
 * @author tongshuai
 * @date 2021-12-02
 */
@RestController
@RequestMapping("/mk/mk")
public class MkController extends BaseController
{
    @Autowired
    private IMkService mkService;

    /**
     * 查询模块列表
     */
    @PreAuthorize("@ss.hasPermi('mk:mk:list')")
    @GetMapping("/list")
    public TableDataInfo list(Mk mk)
    {
        startPage();
        List<Mk> list = mkService.selectMkList(mk);
        return getDataTable(list);
    }

    /**
     * 导出模块列表
     */
    @PreAuthorize("@ss.hasPermi('mk:mk:export')")
    @Log(title = "模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Mk mk)
    {
        List<Mk> list = mkService.selectMkList(mk);
        ExcelUtil<Mk> util = new ExcelUtil<Mk>(Mk.class);
        util.exportExcel(response, list, "模块数据");
    }

    /**
     * 获取模块详细信息
     */
    @PreAuthorize("@ss.hasPermi('mk:mk:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(mkService.selectMkById(id));
    }

    /**
     * 新增模块
     */
    @PreAuthorize("@ss.hasPermi('mk:mk:add')")
    @Log(title = "模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Mk mk)
    {
        return toAjax(mkService.insertMk(mk));
    }

    /**
     * 修改模块
     */
    @PreAuthorize("@ss.hasPermi('mk:mk:edit')")
    @Log(title = "模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Mk mk)
    {
        return toAjax(mkService.updateMk(mk));
    }

    /**
     * 删除模块
     */
    @PreAuthorize("@ss.hasPermi('mk:mk:remove')")
    @Log(title = "模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(mkService.deleteMkByIds(ids));
    }
}
